<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>转工排产查询报表</title>
  <style>
    .el-form-item {
      margin-bottom: 15px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'转工排产查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item prop="plannedstartdate" label="计划发出时间:">
          <el-date-picker v-model="queryInfo.plannedstartdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="承制分厂:" prop="tofactoryid">
          <el-select v-model="queryInfo.tofactoryid" placeholder="请选择承制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主制分厂:" prop="fromfactoryid">
          <el-select v-model="queryInfo.fromfactoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="stepplancreatedate" label="排产时间:">
          <el-date-picker v-model="queryInfo.stepplancreatedate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="排产人:">
          <el-input v-model.trim="queryInfo.planer" placeholder="请输入" clearable style="width: 100px;"></el-input>
        </el-form-item>

        <el-form-item label="是否重点件号:">
          <el-select v-model="queryInfo.isfocusproduct" placeholder="请选择" style="width: 100px;">
            <el-option :key="'是'" :value="'是'" :label="'是'"></el-option>
            <el-option :key="'否'" :value="'否'" :label="'否'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handlerSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
          <template slot="label">
            <el-popover placement="top-start" title="报表过滤规则:" width="300" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>1. 过滤已关闭批次。</p>
              <p>2. 过滤标记为不加工工序。</p>
              <p>3. 只查询转工排产数据。</p>
            </el-popover>
          </template>
        </el-form-item>
      </el-form>

      <!-- 汇总显示区域 -->
      <el-form class="compute-info-zone" :inline="true" :label-position="'left'">
        <el-form-item label="排产零件数:">
          <el-tag>{{computeData.productCount}}</el-tag>
        </el-form-item>

        <el-form-item label="排产工序数:">
          <el-tag>{{computeData.specCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期天数:">
          <el-tag type="danger">{{computeData.delaydaySum}}</el-tag>
        </el-form-item>

        <el-form-item label="超期工序数:">
          <el-tag type="warning">{{computeData.delaySpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="完工工序数:">
          <el-tag type="success">{{computeData.finishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="按时完工数:">
          <el-tag type="success">{{computeData.intimeFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期完成数:">
          <el-tag type="warning">{{computeData.delayFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="未完工序数:">
          <el-tag type="danger">{{computeData.notFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="完成率 = 完工工序数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="完成率:">
            <el-tag type="success">{{computeData.finishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="按时完成率 = 按时完工数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="按时完成率:">
            <el-tag type="success">{{computeData.intimeFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="超期完成率 = 超期完成数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="超期完成率:">
            <el-tag type="warning">{{computeData.delayFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="未完成率 = 未完工序数 ÷ 排产工序数">
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </template>
          <el-form-item label="未完成率:">
            <el-tag type="danger">{{computeData.notFinishRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="\n ">
              <i class="el-icon-info" slot="reference"></i>
              <p>转工发出率 = 已发出工序数 ÷ 工序总数。</p>
            </el-popover>
          </template>
          <el-form-item label="转工发出率:">
            <el-tag>{{computeData.SendOutRate}}%</el-tag>
          </el-form-item>
        </el-form-item>

        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="\n ">
              <i class="el-icon-info" slot="reference"></i>
              <p>发出及时率 = 准时发出工序数 ÷ 已发出工序数</p>
            </el-popover>
          </template>
          <el-form-item label="发出及时率:">
            <el-tag>{{computeData.FCJSL}}%</el-tag>
          </el-form-item>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="主制分厂" prop="originalfactoryname" width="120"></el-table-column>
        <el-table-column label="流水卡号" prop="containername"></el-table-column>
        <el-table-column label="当前工序" prop="currentworkflowstepname" width="140" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="排产工序" prop="planedspecname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="排产人" prop="fullname" width="80"></el-table-column>
        <el-table-column label="排产时间" prop="stepplancreatedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="承制分厂" prop="tofactoryname" width="100px"></el-table-column>
        <el-table-column label="计划发出时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际发出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="计划完成时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="发出超期时间" prop="senddelaydays" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.senddelaydays > 0" style="color:red;font-weight:bold;">
              <i class="el-icon-warning"></i> {{scope.row.senddelaydays}}天
            </div>
            <div v-else>
              {{scope.row.senddelaydays}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="完成超期时间" prop="finishdelaydays" width="100px">
          <template slot-scope="scope">
            <div v-if="scope.row.finishdelaydays > 0" style="color:red;font-weight:bold;">
              <i class="el-icon-warning"></i> {{scope.row.finishdelaydays}}天
            </div>
            <div v-else>
              {{scope.row.finishdelaydays}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="其他信息" width="80px" type="expand">
          <template slot-scope="props">
            <el-descriptions title="其他信息" :column="4" border>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件图号
                </template>
                {{props.row.productname}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 零件名称
                </template>
                {{props.row.productdescription}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 责任工区
                </template>
                {{props.row.fromworkcentername}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i> 数量
                </template>
                {{props.row.qty}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-date"></i> 接收时间
                </template>
                <span v-if="props.row.toacceptdate">{{props.row.toacceptdate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-date"></i> 主制分厂转入时间
                </template>
                <span v-if="props.row.recivedate">{{props.row.recivedate.split('T')[0]}}</span>
              </el-descriptions-item>
            </el-descriptions>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[15,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          tofactoryid: '',// 承制分厂
          fromfactoryid: '',// 主制分厂
          plannedstartdate: '',// 计划发出时间
          productname: '',// 零件图号
          containername: '',// 流水卡号
          planer: '', // 排产人
          isfocusproduct: '', // 是否重点件号
          stepplancreatedate: '',// 主制分厂排产时间
          currentPage: 1,//当前页
          pageSize: 15//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        factoryList: [],//发出分厂
        dataList: [],
        computeData: {},
        // 表单验证
        rules: {
          tofactoryid: [{ required: true, message: '承制分厂不能为空', trigger: 'change' }],
          plannedstartdate: [{ required: true, message: '计划发出时间不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        handlerSearch() {
          this.getData();
          this.getCompute();
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/ContainerStepShipPlan.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        // 查询汇总数据
        async getCompute() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const { data: { data, meta, total } } = await axios.post('../handler/report/ContainerStepShipPlan.ashx?action=getCompute', {
                type: 'getCompute',
                ...this.queryInfo
              })
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.computeData = data[0];
            }
          })
        },
        //导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/ContainerStepShipPlan.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.tofactoryid = factoryid;
        const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD');
        const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD');
        const nextMonday = dayjs().startOf('week').add(1, 'day').add(1, 'week').format('YYYY-MM-DD');
        const nextSunday = dayjs().endOf('week').add(1, 'day').add(1, 'week').format('YYYY-MM-DD');
        this.queryInfo.plannedstartdate = [monday, sunday];
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>